package com.niannian.util;

import java.util.HashMap;
import java.util.Map;

public final class ErrorCode {

	public static final Integer OK = 1;
	public static final Integer FAILED = 0;
	public static final Integer INVALID_PAGE_OR_COUNT = 10004;
	public static final Integer PARAMETERS_INPUT_ERROR = 10005;
	public static final Integer OBJECT_NOT_FOUND = 10006;
	public static final Integer DUPLICATE_OPERATION = 10008;
	public static final Integer FORM_ERRORS = 10009;
	public static final Integer SERVER_ERRORS = 10010;
	public static final Integer LOGIN_REQUIRED = 20001;
	public static final Integer ONLY_ONE_ACC = 20002;
	public static final Integer SMS_CODE_INVALID_OR_EXPIRED = 20004;
	public static final Integer MOBILE_BINDING_FAILED = 20005;
	public static final Integer MALFORMED_REQUEST = 90400;
	public static final Integer NCORRECT_AUTHENTICATION_CREDENTIALS = 90401;
	public static final Integer CSRFTOKEN_INVALID = 90403;
	public static final Integer METHOD_ALLOWED = 90405;
	public static final Integer REQUEST_ACCEPT_HEADER = 00406;
	public static final Integer DATA_TYPE_ERRORS = 90415;
	public static final Integer TOO_MANY_REQUESTS = 90429;
	public static final Integer NOT_CREDENTIALS = 90600;
	public static final Integer NOT_PERMISSION = 90601;

	private static Map<Integer, String> errmap = new HashMap<Integer, String>();

	static {
		errmap.put(OK, "ok");
		errmap.put(FAILED, "操作异常");
		errmap.put(INVALID_PAGE_OR_COUNT, "分页参数无效");
		errmap.put(PARAMETERS_INPUT_ERROR, "参数错误");
		errmap.put(OBJECT_NOT_FOUND, "对象未找到或已被删除");
		errmap.put(DUPLICATE_OPERATION, "重复操作");
		errmap.put(FORM_ERRORS, "django form验证错误");
		errmap.put(SERVER_ERRORS, "服务端错误");
		errmap.put(LOGIN_REQUIRED, "需要登录");
		errmap.put(ONLY_ONE_ACC, "每台设备仅允许一个账号");
		errmap.put(SMS_CODE_INVALID_OR_EXPIRED, "短信验证码无效");
		errmap.put(MOBILE_BINDING_FAILED, "手机号绑定失败");
		errmap.put(MALFORMED_REQUEST, "请求无效");
		errmap.put(NCORRECT_AUTHENTICATION_CREDENTIALS, "鉴权错误");
		errmap.put(CSRFTOKEN_INVALID, "无效csrftoken");
		errmap.put(METHOD_ALLOWED, "http请求方法无效, 必须是get/post/put/delete");
		errmap.put(REQUEST_ACCEPT_HEADER, "请求头无效");
		errmap.put(DATA_TYPE_ERRORS, "数据类型不支持");
		errmap.put(TOO_MANY_REQUESTS, "请求过多");
		errmap.put(NOT_CREDENTIALS, "未提供鉴权");
		errmap.put(NOT_PERMISSION, "操作权限不够");

	}

	public static String GetErrorMsg(int errCode) {
		String msg = null;
		msg = errmap.get(errCode);

		if (msg == null) {
			msg = "未知错误(" + errCode + ")";
		}

		return msg;
	}

}
